--[[/**
-- * 
 * 改变能量，溢出则增加buff
 *
 * @author heyang
-- *
-- */]]

---@class BuffEffect463100 : BaseBuffEffect
BuffEffect463100 = ClientFight.CreateClass("BuffEffect463100", ClientFight.BaseBuffEffect)
local t = BuffEffect463100
t.BuffEffect463100_RE_DAMAGE = "BuffEffect463100_RE_DAMAGE_";
t.FighterDamageBuffEffect463100_RE_DAMAGE = "FighterDamageBuffEffect463100_RE_DAMAGE_";
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local result = parameters[3];
    if (result.damage == 0) then
        return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);

    end
    if (not AttackUtils.isDamage(result.state)) then
        return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);

    end
    local damage = result.damage;
    result.damage = 0;
    local oldValue = buff.effectParams[t.BuffEffect463100_RE_DAMAGE] or 0;
    buff.effectParams[t.BuffEffect463100_RE_DAMAGE] = oldValue + damage;
    local attacker = parameters[1];
    if (attacker:isSummons()) then
        local summonsCreater = attacker.summonsCreater();
        if (summonsCreater ~= nil) then
            attacker = summonsCreater;--统计为主人的伤害
        end
    end
    --记录下来谁造成的伤害
    local attackerMap = buff.effectParams[t.FighterDamageBuffEffect463100_RE_DAMAGE] or {};
    buff.effectParams[t.FighterDamageBuffEffect463100_RE_DAMAGE] = attackerMap;
    local attValue = attackerMap[attacker.fighterId] or 0;
    attackerMap[attacker.fighterId] = attValue + damage;
    SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
            .. buff.modelId .. " 触发吸收伤害,buff结束时再结算: " .. damage .. "  已吸收总伤害: " .. (oldValue .. damage));
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()